//
//  HDCameraBottomBar.swift
//  HuaDaoPeifu
//
//  Created by Erickson on 16/3/31.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import UIKit

protocol HDCameraBottomBarDelegate:class {
    func didSelectAlbum()
    func didSelectShutter()
    func didSelectFinished()
}

class HDCameraBottomBar: UIView {

    weak var delegate:HDCameraBottomBarDelegate?
    let certain = UIButton()
    let shutter = HDShutterView()
    
    init() {
        
        super.init(frame:CGRect.zero)
        self.backgroundColor = HDCameraColor.bottomBarColor

        setupViews()
    }
 
    func setFinishedTitle(_ number:Int) {
        var title = ""
        if number > 0 {
            title = "完成(\(number))"
        }
        certain.setTitle(title, for: UIControlState())
    }
    
    func setupViews() {
        let album = UIButton()
        album.setImage(UIImage(named: "拍照_photo"), for: UIControlState())
        album.addTarget(self, action: #selector(albumAction(_:)), for: .touchUpInside)
        self.addSubview(album)
        album.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.width.equalTo(album.currentImage!.size.width)
            make.height.equalTo(album.currentImage!.size.height)
            make.left.equalTo(10)
        }
        
        
        self.addSubview(shutter)

        shutter.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self)
            make.width.equalTo(shutter.rect.size.width)
            make.height.equalTo(shutter.rect.size.height)
        }
        shutter.delegate = self
        
        
        
        
        self.addSubview(certain)
        certain.addTarget(self, action: #selector(HDCameraBottomBar.finishedAction), for: .touchUpInside)
//        certain.hidden = true
        certain.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(18)
            make.right.equalTo(-10)
        }
        
    }
    func finishedAction() {
        delegate?.didSelectFinished()
    }
    
    func albumAction(_ sender:UIButton) {
        delegate?.didSelectAlbum()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


extension HDCameraBottomBar : HDShutterViewDelegate {
    func didClickShutter() {
        delegate?.didSelectShutter()
    }
}
